package com.cheyun.netsalev3.tencenttim.profile.clipimagedemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

/**
 * @ClassName: ClipImageBorderView
 * @Description:
 * @author xiechengfa2000@163.com
 * @date 2015-5-10 下午10:22:53
 */
public class ClipImageBorderView extends View {
	/**
	 * 水平方向与View的边�?
	 */
	private int mHorizontalPadding;
	/**
	 * 垂直方向与View的边�?
	 */
	private int mVerticalPadding;
	/**
	 * 绘制的矩形的宽度
	 */
	private int mWidth;
	/**
	 * 边框的颜色，默认为白�?
	 */
	private int mBorderColor = Color.parseColor("#FEF801");
	/**
	 * 边框的宽�?单位dp
	 */
	private int mBorderWidth = 1;

	private boolean isBigImg = false;

	private float scaleHeight = 0;

	private Paint mPaint;
	private int isrect = 0;

	private int screeWidth;
	private int screeHeight;

	public ClipImageBorderView(Context context,int isrect) {
		this(context, null,isrect);
	}

	public ClipImageBorderView(Context context, AttributeSet attrs,int isrect) {
		this(context, attrs, 0,isrect);
	}

	public ClipImageBorderView(Context context, AttributeSet attrs, int defStyle,int isrect) {
		super(context, attrs, defStyle);
		this.isrect = isrect;
		mBorderWidth = (int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, mBorderWidth, getResources()
						.getDisplayMetrics());
		mPaint = new Paint();
		mPaint.setAntiAlias(true);

		WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		screeWidth = display.getWidth();
		screeHeight = display.getHeight();
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// 计算矩形区域的宽�?
		mWidth = getWidth() - 2 * mHorizontalPadding;
		if(isrect == 0)return;
		if(isrect ==1){
			mVerticalPadding = (getHeight() - mWidth * 200 / 750) / 2;
		}else if(isrect == 2){
			mVerticalPadding = (getHeight() - mWidth * 118 / 135) / 2;
		}else if(isrect == 3){
			mVerticalPadding = (getHeight()-mWidth*54/80)/2;
		}else if(isrect == 4){
			mVerticalPadding = (getHeight()-mWidth*54/80)/2;
		}else if(isrect == 5){
			mVerticalPadding = (getHeight()-mWidth*240/750)/2;
		}else if(isrect == 6){
			mVerticalPadding = (getHeight()-mWidth*150/750)/2;
		}else if(isrect == 10){
			mVerticalPadding = (getHeight() - mWidth * 500 / 500) / 2;
		}else if(isrect == 20 || isrect == 21){
			mVerticalPadding = (screeHeight - mWidth * 1082 / 500) / 2;
			if(mVerticalPadding<0){
				mVerticalPadding = 0;
			}
			Log.e("getHeight",getHeight()+"" );
		}else if(isrect !=0){
			mVerticalPadding = (getHeight() - mWidth * 256 / 750) / 2;
		}
		mPaint.setColor(mBorderColor);
		mPaint.setStrokeWidth(mBorderWidth);
		mPaint.setStyle(Style.STROKE);
		canvas.drawRect(mHorizontalPadding, mVerticalPadding, getWidth()
				- mHorizontalPadding, getHeight() - mVerticalPadding, mPaint);
		Log.e("clipimageborder", "onDraw: "+mHorizontalPadding+","+mVerticalPadding+","+ (getWidth()- mHorizontalPadding)+","+(getHeight() - mVerticalPadding));
		super.onDraw(canvas);
	}

	public void setHorizontalPadding(int mHorizontalPadding,float scaleHeight) {
		this.mHorizontalPadding = mHorizontalPadding;
		this.scaleHeight = scaleHeight;
	}

	public void setIsBigImg(boolean isBig) {
		this.isBigImg = isBig;
	}
	public void settype(int isrect){
		this.isrect = isrect;


	}
}
